package com.online.music.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.online.music.common.Result;
import com.online.music.entity.dto.AlbumAddSongsDTO;
import com.online.music.entity.po.Song;
import com.online.music.utils.UserContextUtil;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import com.online.music.service.IAlbumService;
import com.online.music.entity.po.Album;

import org.springframework.web.bind.annotation.RestController;


/**
 * @Author: Leno
 * @Date: 2025-01-31
 * @Description: album接口
 */
@RequiredArgsConstructor
@Slf4j
@Tag(name = "album接口")
@RestController
@RequestMapping("/album")
public class AlbumController {

    private final IAlbumService albumService;

    @Operation(summary = "查询所有Album")
    @GetMapping
    public Result<List<Album>> findAll() {
        return Result.success(albumService.list());
    }

    @Operation(summary = "根据id查询Album")
    @GetMapping("/{id}")
    public Result<Album> findOne(@PathVariable Long id) {
        return Result.success(albumService.getById(id));
    }

    @Operation(summary = "根据分页查询Album")
    @GetMapping("/page")
    public Result<Page<Album>> findPage(@RequestParam Integer pageNum, @RequestParam Integer pageSize, Album album) {
        return albumService.findPage(pageNum, pageSize, album);
    }

    @Operation(summary = "添加或修改Album")
    @PostMapping
    public Result<Boolean> save(@RequestBody Album album) {
        album.setUserId(UserContextUtil.getUserId());
        return Result.success(albumService.saveOrUpdate(album));
    }

    @Operation(summary = "根据id批量删除Album")
    @DeleteMapping("/del/batch")
    public Result<String> deleteBatch(@RequestBody List<Long> ids) {
        return albumService.deleteBatch(ids);
    }

    @Operation(summary = "向专辑中添加歌曲")
    @PostMapping("/add/songs")
    public Result<String> addSong(@RequestBody AlbumAddSongsDTO albumAddSongsDTO) {
        return albumService.addSong(albumAddSongsDTO);
    }

    @Operation(summary = "从专辑中删除歌曲")
    @PostMapping("/remove/songs")
    public Result<String> removeSong(@RequestBody AlbumAddSongsDTO albumAddSongsDTO) {
        return albumService.removeSong(albumAddSongsDTO);
    }

    @Operation(summary = "获取专辑的歌曲列表")
    @GetMapping("/get/songs/{id}")
    public Result<List<Song>> getAlbumSongs(@PathVariable Long id) {
        return albumService.getAlbumSongs(id);
    }

    @Operation(summary = "获取专辑可用歌曲")
    @GetMapping("/available/songs")
    public Result<List<Song>> getAvailableSongs() {
        return albumService.getAvailableSongs();
    }

}
